package com.box2dwrapper.object
{
	import Box2D.Collision.Shapes.b2PolygonDef;
	import Box2D.Dynamics.Joints.b2RevoluteJointDef;
	import Box2D.Dynamics.b2BodyDef;
	
	import com.box2dwrapper.view.core.AbstractView;
	
	import flash.display.DisplayObject;

	public class Box extends AbstractObject
	{
		public static const DYNAMIC:String = "dynamic";
		public static const STATIC:String = "static";
		
		public function Box(strType:String = "dynamic", numDensity:Number = 1.0, numFriction:Number = 0.3, numRestitution:Number = 0.2)
		{
			bodyDef = new b2BodyDef();			
			polyDef = new b2PolygonDef();
			
			type = strType;
			density = numDensity;
			friction = numFriction;
			restitution = numRestitution;
		}
		
		public function scale(numWidth:Number = 100, numHeight:Number = 100):void
		{
			width = numWidth;
			height = numHeight;
			polyDef.SetAsBox((numWidth * 0.5)/AbstractView.SCALE, (numHeight * 0.5)/AbstractView.SCALE);
		}
		
		public function set density(value:Number) { polyDef.density = value }
		public function get density():Number { return polyDef.density }
		
		public function set friction(value:Number) { polyDef.friction = value }
		public function get friction():Number { return polyDef.friction }
		
		public function set restitution(value:Number) { polyDef.restitution = value }
		public function get restitution():Number { return polyDef.restitution }
		
		public function set type(boxType:String):void
		{
			if(boxType == "static"){
				polyDef.density = 0;
			}else if(boxType == "dynamic"){
				polyDef.density = density;
				polyDef.friction = friction;
				polyDef.restitution = restitution;
			}
		}
		
	}
}